﻿// Copyright (c) ZeroC, Inc.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using IceRpc;

namespace GreeterServer;
public class CallBackConnection : IInvoker
{
    private volatile IInvoker? _invoker;
    public async Task<IncomingResponse> InvokeAsync(OutgoingRequest request, CancellationToken cancellationToken = default)
    {
        if (_invoker is IInvoker invoker)
        {
            try
            {
                return await invoker.InvokeAsync(request, cancellationToken);
            }
            catch (ObjectDisposedException)
            {

                //throw;
            }
        }
        throw new DispatchException(StatusCode.NotFound, "the callback not connection");
    }

    public void SetInvoker(IInvoker invoker) => _invoker = invoker;
    public bool isInit
    {
        get
        {
            return _invoker != null;
        }
    }
}
